package com.bxd.baodan.item;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 车险实体类
 * 
 * @author Administrator
 * 
 */
public class CarInsuranceItem extends RequiementItem {
	/** 免赔 */
	public static final int INSURETYPE_MIANPEI = 0;
	/** 无过责任险 */
	public static final int INSURETYPE_WUGUO = 1;
	/** 玻璃单独破碎险 */
	public static final int INSURETYPE_BOLI = 2;
	/** 车险损失 */
	public static final int INSURETYPE_CARSUNSHI = 3;
	/** 全车盗抢险 */
	public static final int INSURETYPE_CARBEIDAO = 4;
	/** 车辆划痕险 */
	public static final int INSURETYPE_CARHUAHEN = 5;
	/** 自燃损失险 */
	public static final int INSURETYPE_CARZIRAN = 6;
	/** 车上人员责任险 */
	public static final int INSURETYPE_CARRENYUAN = 7;
	// 推荐分类
	public static final int INSURE_KIND_NORMAL = 0;// 普通类型
	public static final int INSURE_KIND_MONEY = 1;// 经济类型
	public static final int INSURE_KIND_LOW = 2;// 无忧类型

	private String citycode;// 城市码
	private String procode;// 省份
	private String carprice;// 车辆购买价格
	private String plateNumber;//车牌类型，如豫A
	private int cardanger;// 车辆是否出险 0未出 1出险
	private String buydate;// 购车时间
	private int driving_experience;// 驾驶经验： 0新手上路1驾驶多年
	private int caroldornew;// 车辆新旧：0旧车练手 1刚买的新车
	private int caruseway;// 用车方式：0经常市区驾驶1经常跑长途2平时不开偶尔用
	private int seatnumber;// 车座数 0:7座以下 1：7座 2：9座
	private String thirdliability;// 第三方责任险
	private boolean contributing;// 不计免赔责任险
	private boolean withoutliability;// 无过责任险
	private int glassbreak;// 玻璃单独破碎险 0不投保 1国产 2进口
	private boolean carlossy;// 车辆损失险
	private boolean carsteal;// 车辆盗抢险
	private int carscratch;// 车辆划痕险 0不选 1：2000 2：5000 3：1万 4：2万
	private boolean burning;// 自然损失险
	private boolean carpeople;// 车上人员责任险

	// 不计免赔特约险
	public String getCitycode() {
		return citycode;
	}

	public void setCitycode(String citycode) {
		this.citycode = citycode;
	}

	public String getProcode() {
		return procode;
	}

	public void setProcode(String procode) {
		this.procode = procode;
	}

	public String getCarprice() {
		return carprice;
	}

	public void setCarprice(String carprice) {
		this.carprice = carprice;
	}

	public int getCardanger() {
		return cardanger;
	}

	public void setCardanger(int cardanger) {
		this.cardanger = cardanger;
	}

	public String getBuydate() {
		return buydate;
	}

	public void setBuydate(String buydate) {
		this.buydate = buydate;
	}

	public int getDriving_experience() {
		return driving_experience;
	}
	public String getSeatnumberString() {
		String ss = "7座以下";
		switch (this.getSeatnumber()) {
		case 0:
			ss = "7座以下";
			break;
		case 1:
			ss = "7座";
			break;
		case 2:
			ss = "9座";
			break;
		default:
			break;
		}
		return ss;
	}
	public String getCarscratchString() {
		String ss = "";
		// 车辆划痕险 0不选 1：2000 2：5000 3：1万 4：2万
		switch(this.carscratch){
		case 1:
			ss = "2000元";
			break;
		case 2:
			ss = "5000元";
			break;
		case 3:
			ss = "1万元";
			break;
		case 4:
			ss = "2万元";
			break;
		}
		return ss;
	}
	public void setDriving_experience(int driving_experience) {
		this.driving_experience = driving_experience;
	}

	public int getCaroldornew() {
		return caroldornew;
	}

	public void setCaroldornew(int caroldornew) {
		this.caroldornew = caroldornew;
	}

	public int getCaruseway() {
		return caruseway;
	}

	public void setCaruseway(int caruseway) {
		this.caruseway = caruseway;
	}

	public int getSeatnumber() {
		return seatnumber;
	}

	public void setSeatnumber(int seatnumber) {
		this.seatnumber = seatnumber;
	}

	public String getThirdliability() {
		return thirdliability;
	}

	public void setThirdliability(String thirdliability) {
		this.thirdliability = thirdliability;
	}

	public boolean isContributing() {
		return contributing;
	}

	public void setContributing(boolean contributing) {
		this.contributing = contributing;
	}

	public boolean isWithoutliability() {
		return withoutliability;
	}

	public void setWithoutliability(boolean withoutliability) {
		this.withoutliability = withoutliability;
	}

	public int getGlassbreak() {
		return glassbreak;
	}

	public void setGlassbreak(int glassbreak) {
		this.glassbreak = glassbreak;
	}

	public boolean isCarlossy() {
		return carlossy;
	}

	public void setCarlossy(boolean carlossy) {
		this.carlossy = carlossy;
	}

	public boolean isCarsteal() {
		return carsteal;
	}

	public void setCarsteal(boolean carsteal) {
		this.carsteal = carsteal;
	}

	public int getCarscratch() {
		return carscratch;
	}

	public void setCarscratch(int carscratch) {
		this.carscratch = carscratch;
	}

	public boolean isBurning() {
		return burning;
	}

	public void setBurning(boolean burning) {
		this.burning = burning;
	}

	public boolean isCarpeople() {
		return carpeople;
	}

	public void setCarpeople(boolean carpeople) {
		this.carpeople = carpeople;
	}

	@Override
	public String toString() {
		return "CarInsuranceItem [citycode=" + citycode + ", procode="
				+ procode + ", carprice=" + carprice + ", cardanger="
				+ cardanger + ", buydate=" + buydate + ", driving_experience="
				+ driving_experience + ", caroldornew=" + caroldornew
				+ ", caruseway=" + caruseway + ", seatnumber=" + seatnumber
				+ ", thirdliability=" + thirdliability + ", contributing="
				+ contributing + ", withoutliability=" + withoutliability
				+ ", glassbreak=" + glassbreak + ", carlossy=" + carlossy
				+ ", carsteal=" + carsteal + ", carscratch=" + carscratch
				+ ", burning=" + burning + ", carpeople=" + carpeople + "]";
	}

	/**
	 * 参数index说明 0:不计免赔特约险 1：无过责任险 2：玻璃单独破碎险 3：车辆损失险 4：全车盗抢险 5:车辆划痕险 6:自燃损失险
	 * 7:车上人员责任险
	 * */
	public boolean isSelect(int index, int type) {
		int stander = 0;// 0代表无忧型，1代表经济型，2代表基本型
		switch (type) {
		case INSURE_KIND_NORMAL:
			stander = 5;
			break;
		case INSURE_KIND_MONEY:
			stander = 3;
			break;
		case INSURE_KIND_LOW:
			stander = 2;
			break;
		default:
			break;
		}
		return getTypeCount().get(index) >= stander;
	}

	public List<Integer> getTypeCount() {
		// //免赔
		// public static final int INSURETYPE_MIANPEI = 0;
		// //无过责任险
		// public static final int INSURETYPE_WUGUO = 1;
		// //玻璃单独破碎险
		// public static final int INSURETYPE_BOLI = 2;
		// //车险损失
		// public static final int INSURETYPE_CARSUNSHI = 3;
		// //全车盗抢险
		// public static final int INSURETYPE_CARBEIDAO = 4;
		// //车辆划痕险
		// public static final int INSURETYPE_CARHUAHEN = 5;
		// //自燃损失险
		// public static final int INSURETYPE_CARZIRAN= 6;
		// //车上人员责任险
		// public static final int INSURETYPE_CARRENYUAN= 7;
		List<Integer> arrayList = new ArrayList<Integer>();
		// 根据不同的条件判断是否选中某些选项
		for (int i = 0; i < 8; i++) {// 一共八项内容
			arrayList.add(0);
		}
		// 购车价格
		if (Double.parseDouble(carprice) > 7
				&& Double.parseDouble(carprice) <= 10) {
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 1);
		} else if (Double.parseDouble(carprice) > 10
				&& Double.parseDouble(carprice) <= 15) {
			// 不记责任险
			arrayList
					.set(INSURETYPE_WUGUO, arrayList.get(INSURETYPE_WUGUO) + 1);
			// 车辆损失
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 1);
		} else if (Double.parseDouble(carprice) > 15
				&& Double.parseDouble(carprice) <= 30) {
			// 不记责任险
			arrayList
					.set(INSURETYPE_WUGUO, arrayList.get(INSURETYPE_WUGUO) + 1);
			// 统计玻璃单独破碎险
			arrayList.set(INSURETYPE_BOLI, arrayList.get(INSURETYPE_BOLI) + 1);
			// 划痕险
			arrayList.set(INSURETYPE_CARHUAHEN,
					arrayList.get(INSURETYPE_CARHUAHEN) + 1);
			// 车辆损失
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 3);
		} else if (Double.parseDouble(carprice) > 30) {
			for (int i = 0; i < 8; i++) {
				arrayList.set(i, arrayList.get(i) + 1);
			}
		}
		// 行驶路况
		switch (caruseway) {
		case 1:// 郊外
			arrayList.set(INSURETYPE_CARRENYUAN,
					arrayList.get(INSURETYPE_CARRENYUAN) + 1);
			arrayList.set(INSURETYPE_BOLI, arrayList.get(INSURETYPE_BOLI) + 1);
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 1);
			// 不记责任险
			arrayList
					.set(INSURETYPE_WUGUO, arrayList.get(INSURETYPE_WUGUO) + 1);
			break;
		case 0:// 市区
			arrayList.set(INSURETYPE_CARHUAHEN,
					arrayList.get(INSURETYPE_CARHUAHEN) + 1);
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 3);
			arrayList.set(INSURETYPE_WUGUO,
					arrayList.get(INSURETYPE_WUGUO) + 1);
			break;
		case 2:// 偶尔开开
			arrayList.set(INSURETYPE_BOLI, arrayList.get(INSURETYPE_BOLI) + 1);
			arrayList.set(INSURETYPE_CARBEIDAO,
					arrayList.get(INSURETYPE_CARBEIDAO) + 1);
			arrayList.set(INSURETYPE_CARZIRAN,
					arrayList.get(INSURETYPE_CARZIRAN) + 1);
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 1);
			break;
		default:
			break;
		}
		// 新旧程度
		switch (caroldornew) {
		case 0:// 旧车
			arrayList.set(INSURETYPE_CARZIRAN,
					arrayList.get(INSURETYPE_CARZIRAN) + 2);
			arrayList
					.set(INSURETYPE_WUGUO, arrayList.get(INSURETYPE_WUGUO) + 1);
			break;
		case 1:// 新车
			arrayList.set(INSURETYPE_CARBEIDAO,
					arrayList.get(INSURETYPE_CARBEIDAO) + 1);
			arrayList.set(INSURETYPE_CARHUAHEN,
					arrayList.get(INSURETYPE_CARHUAHEN) + 1);
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 3);

			break;
		default:
			break;
		}
		// 驾驶经验
		switch (driving_experience) {
		case 0:// 新手
			arrayList.set(INSURETYPE_CARHUAHEN,
					arrayList.get(INSURETYPE_CARHUAHEN) + 2);
			arrayList.set(INSURETYPE_CARRENYUAN,
					arrayList.get(INSURETYPE_CARRENYUAN) + 3);
			arrayList.set(INSURETYPE_CARSUNSHI,
					arrayList.get(INSURETYPE_CARSUNSHI) + 3);
			arrayList
					.set(INSURETYPE_WUGUO, arrayList.get(INSURETYPE_WUGUO) + 1);
			break;
		case 1:// 熟手
			arrayList.set(INSURETYPE_CARHUAHEN,
					arrayList.get(INSURETYPE_CARHUAHEN) + 1);
			break;

		default:
			break;
		}
		// 购车时间
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar1 = Calendar.getInstance();
		Calendar calendar2 = Calendar.getInstance();
		try {
			Date date = sdf.parse(buydate);
			calendar1.setTime(date);
			calendar2.setTime(new Date());
			// 判断时间差几年
			long milliseconds1 = calendar1.getTimeInMillis();
			long milliseconds2 = calendar2.getTimeInMillis();
			long years = (milliseconds2 - milliseconds1)
					/ (24 * 60 * 60 * 1000 * 365);
			if (years < 5) {
				arrayList.set(INSURETYPE_CARHUAHEN,
						arrayList.get(INSURETYPE_CARHUAHEN) + 1);
			}
			if (years > 3) {
				arrayList.set(INSURETYPE_CARZIRAN,
						arrayList.get(INSURETYPE_CARZIRAN) + 2);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return arrayList;
	}


	public String getPlateNumber() {
		return plateNumber;
	}

	public void setPlateNumber(String plateNumber) {
		this.plateNumber = plateNumber;
	}
}
